//url

function bidModeText(bidMode){
	var btext = "--";
	if(bidMode=="1")btext = "正向多次竞价";
	if(bidMode=="2")btext = "反向多次竞价";
	if(bidMode=="3")btext = "正向一次报价";
	if(bidMode=="4")btext = "反向一次报价";
	if(bidMode=="5")btext = "正向份额报价";
	if(bidMode=="6")btext = "反向份额报价";
	if(bidMode=="7")btext = "荷兰式竞价";
	return btext;
}

function itemStatusTxt(itemStatus){
	var iStatusTxt ="";
	if(itemStatus=="0"){
		iStatusTxt ="未发布";
	}else if(itemStatus=="1"){
		iStatusTxt ="审核中";
	}else if(itemStatus=="2"){
		iStatusTxt ="已发布";
	}else if(itemStatus=="3"){
		iStatusTxt ="暂停中";
	}else if(itemStatus=="4"){
		iStatusTxt ="发布未通过";
	}else if(itemStatus=="5"){
		iStatusTxt ="竞价成功";
	}else if(itemStatus=="6"){
		iStatusTxt ="竞价失败";
	}else if(itemStatus=="9"){
		iStatusTxt ="已结束";
	}
	
	return iStatusTxt;
}
//发布活动：将活动的状态改为2，并将该活动下所有的标的的状态改为2，并把所有标的加载缓存
function pubSessionSubmit(sessionId){
	//var this_url = ctx+spaceDomain+"session/rf/"+sessionId;
	var this_url = ctx+spaceDomain+"session/start/"+sessionId;
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   pubSessionBack(myData.flag,myData.msg);
		  }
	});		
}

//暂停活动：将活动的状态改为0，并将该活动下所有的标的的状态改为0，并把所有标的缓存清掉
function pauseSessionSubmit(sessionId){
	var this_url = ctx+spaceDomain+"session/stop/"+sessionId;
	//var this_url = ctx+spaceDomain+"session/pause/"+sessionId;
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   pauseSessionBack(myData.flag,myData.msg);
		  }
	});		
}
//继续活动
function continueSessionSubmit(sessionId){
	var this_url = ctx+spaceDomain+"session/continue/"+sessionId;
	//var this_url = ctx+spaceDomain+"session/pause/"+sessionId;
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   continueSessionBack(myData.flag,myData.msg);
		  }
	});		
}
//发布标的：将标的的状态改为2，并更新缓存.
function pubItemSubmit(itemId){
	//var this_url = ctx+spaceDomain+"item/rf/"+itemId;
	var this_url = ctx+spaceDomain+"item/start/"+itemId;
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   pubItemBack(myData.flag,myData.msg);
		  }
	});		
}
//暂停标的
function pauseItemSubmit(itemId){
	var this_url = ctx+spaceDomain+"item/stop/"+itemId;
	//var this_url = ctx+spaceDomain+"item/pause/"+itemId;
	//alert(this_url);
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   pauseItemBack(myData.flag,myData.msg);
		  },
		  error:function(XMLHttpRequest, textStatus, errorThrown){
			  //alert(XMLHttpRequest.status);
              //alert(XMLHttpRequest.readyState);
              //alert(textStatus);
			  //alert("请检查服务器！");
		  }
	});		
}
//继续启用标的
function continueItemSubmit(formName){
	var itemId = $('#'+formName).find("input[name='itemId']").val();
	var this_url = ctx+spaceDomain+"item/continue/"+itemId;
	//var this_url = ctx+spaceDomain+"item/pause/"+itemId;
	$.ajax({
		   type:'get',
		   url:this_url,
		   data:$("#"+formName).serialize(),
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   continueItemBack(myData.flag,myData.msg);
		  }
	});		
}
//恢复标的.
function restoreItemSubmit(formName){
	var this_url = ctx+spaceDomain+"item/restore";
	//var this_url = ctx+spaceDomain+"item/restore/"+itemId;
	$.ajax({
		   type:'post',
		   url:this_url,
		   data:$("#"+formName).serialize(),
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   restoreItemBack(myData.flag,myData.msg);
		  }
	});		
}
function getContent(objId,objType){
	var this_url = ctx+spaceDomain+"session/rf/"+objId;
	//var this_url = ctx+spaceDomain+"content/rf/"+objId+"/"+objType;
	//alert(this_url);
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.total);
			   getContentBack(myData.entity,objType);
		  }
	});	
}

function getPara(objId,objType){
	var this_url = "";
	if(objType == null ||objType == "" || objType == "printId"){
		this_url = ctx+spaceDomain+"para/rf/"+objId;
	}else if(objType == "sessionId"){
		this_url = ctx+spaceDomain+"para/byObjId/"+objId+"/"+objType;
	}else if(objType == "itemId"){
		this_url = ctx+spaceDomain+"para/byObjId/"+objId+"/"+objType;
	}
	//alert(this_url);
	$.ajax({
		   type:'get',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.msg);
			   getParaBack(myData);
		  }
	});	
}

function baojiaSubmit(itemId,price){
	var this_url = ctx+spaceDomain+"session/rf/"+sessionId;
	//var this_url = ctx+spaceDomain+"item/baojia/"+itemId+"/"+price;
	$.ajax({
		   type:'put',
		   url:this_url,
		   dataType:'json',
		   success: function(myData){
			   //alert(myData.flag);
			   baojiaBack(myData.flag,myData.msg);
		  }
	});			
}

function dynLoad(ids){
	var itermIds = "";
	$("input[name=ids]").each(function(){
		itermIds += $(this).val()+",";
	});
	alert(itermIds);
}

//活动状态
function sessionStatusText(status){
	var stext = "--";
	if(status=="0")stext = "未发布";
	if(status=="1")stext = "审核中";
	if(status=="2")stext = "已发布";
	if(status=="3")stext = "暂停中";
	if(status=="4")btext = "发布未通过";
	if(status=="9")stext = "已结束";
	return stext;
}

//保证金控制方式
function bailCtrlText(bCtrl){
	var btext = "--";
	if(bCtrl=="0")btext = "不交保证金";
	if(bCtrl=="1")btext = "活动固定保证金制";
	if(bCtrl=="2")btext = "每个标的收取固定保证金制";
	if(bCtrl=="3")btext = "按设置的保证金比例扣除竞买人的保证金";
	return btext;
}

//竞买人激活状态
function applayStatusText(bCtrl){
	var btext = "--";
	if(bCtrl=="0")btext = "未激活";
	if(bCtrl=="1")btext = "已激活";
	return btext;
}

/*
 * 计算下一下时间点
 */
function getNextTime(startTime,ss){
	//alert(startTime+"---"+ss);
	var date = new Date(startTime.replace(/-/g, " / "));//要计算的时间
	var StateTimeofMinute = date.getTime();//.getMinutes();//获取分钟属性
	date = new Date(StateTimeofMinute+ss*1000); //设置分钟属性
	return date.format("yyyy-MM-dd hh:mm:ss");
}

function initMyTime(timeId,timeValue){
	//createMyTimeOption(timeId);
	 $("#"+timeId).val(timeValue);
	 var year = timeValue.substring(0,4);
	 $("#"+timeId+"_y").val(timeValue.substring(0,4));
	 $("#"+timeId+"_m").val(timeValue.substring(5,7));
	 $("#"+timeId+"_d").val(timeValue.substring(8,10));
	 $("#"+timeId+"_hh").val(timeValue.substring(11,13));
	 $("#"+timeId+"_mm").val(timeValue.substring(14,16));
	 $("#"+timeId+"_ss").val(timeValue.substring(17,19));
}


function createMyTimeOption(timeId){
	var obj=document.getElementById(timeId+'_y');
	obj.options.add(new Option("2016","2016"));
	obj.options.add(new Option("2017","2017"));
	obj.options.add(new Option("2018","2018"));
	
	var obj=document.getElementById(timeId+'_m');
	for(i=1;i<=12;i++){
		v=i;
		if(i<10) v="0"+i;
		obj.options.add(new Option(v,v));
	}
	var obj=document.getElementById(timeId+'_d');
	for(i=1;i<=31;i++){
		v=i;
		if(i<10) v="0"+i;
		obj.options.add(new Option(v,v));
	}	
	var obj=document.getElementById(timeId+'_hh');
	for(i=0;i<24;i++){
		v=i;
		if(i<10) v="0"+i;
		obj.options.add(new Option(v,v));
	}
	var obj=document.getElementById(timeId+'_mm');
	for(i=0;i<60;i++){
		v=i;
		if(i<10) v="0"+i;
		obj.options.add(new Option(v,v));
	}
	var obj=document.getElementById(timeId+'_ss');
	for(i=0;i<60;i++){
		v=i;
		if(i<10) v="0"+i;
		obj.options.add(new Option(v,v));
	}
}

function setMyTime(timeId){
	var y= $('#'+timeId+"_y").val();
	var m= $('#'+timeId+"_m").val();
	var d= $('#'+timeId+"_d").val();
	var hh= $('#'+timeId+"_hh").val();
	var mm= $('#'+timeId+"_mm").val();
	var ss= $('#'+timeId+"_ss").val();
	var dd = y+"-"+m+"-"+d+" "+hh+":"+mm+":"+ss;
	$('#'+timeId).val(dd);
}

function checkIt(obj,flag){
	var msg="的格式不对";
	var dv = obj.value;
	if(flag=="y"){
		if(dv<2016 || dv>2030){
			alert("年"+msg);
			return;
		}
	}else if(flag=="m"){
		if(dv<=0 || dv>12){
			alert("月"+msg);
			obj.value='';
			return;
		}
		add0(obj);
	}else if(flag=="d"){
		if(dv<=0 || dv>31){
			alert("日"+msg);
			obj.value='';
			return;
		}
		add0(obj);
	}else if(flag=="hh"){
		if(dv<0 || dv>24){
			alert("时"+msg);
			obj.value='00';
			return;
		}
		add0(obj);
	}else if(flag=="mm"){
		if(dv<0 || dv>60){
			alert("分"+msg);
			obj.value='00';
			return;
		}
		add0(obj);
	}else if(flag=="ss"){
		if(dv<0 || dv>60){
			alert("秒"+msg);
			obj.value='00';
			return;
		}
		add0(obj);
	}
}

//月、日、时、分、秒 一位的话，补0
function add0(obj){
	if(obj.value.length==1){
		var dv = "0"+obj.value;
		obj.value = dv;
	}
}